package net.obxlabs.tweetpad.behaviour;

import java.util.*;
import net.nexttext.*;
import net.nexttext.behaviour.*;
import net.obxlabs.tweetpad.*;

public class FollowThumb extends AbstractAction {
	private static Map<TextObject, Tweet> links;
	
	static {
		links = Collections.synchronizedMap(new HashMap<TextObject, Tweet>());
	}
	
	public static void link(TextObject to, Tweet tweet) {
		if (!links.containsKey(to)) {
			links.put(to, tweet);
		}
	}
	
	public static void unlink(TextObject to) {
		if (links.containsKey(to)) {
			links.remove(to);
		}
	}
	
	public static boolean isLinked(TextObject to) {
		return links.containsKey(to);
	}
	
	public static Tweet getLink(TextObject to) {
		return links.get(to);
	}
	
	public ActionResult behave(TextObject to) {
		if (links.containsKey(to)) {
			float thumbY = links.get(to).getY();
			Vector3 newPos = to.getPosition().get();
			newPos.y = thumbY+Tweet.TEXT_OFFSET;
			to.getPosition().set(newPos);
			return new ActionResult(false, true, false);
		}
		
		return new ActionResult(true, true, false);
	}
}
